package com.carleasoft.mps.cms.business.train.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.carleasoft.mps.cms.business.train.bean.entity.TrainExam;
import com.carleasoft.mps.cms.business.train.bean.entity.TrainPlan;
import com.carleasoft.mps.cms.business.train.bean.entity.TrainPlanActivity;
import com.carleasoft.mps.cms.business.train.bean.entity.TrainScore;
import com.carleasoft.mps.cms.business.train.bean.po.*;
import com.carleasoft.mps.cms.business.train.bean.vo.*;
import com.carleasoft.mps.cms.business.train.service.TrainExamService;
import com.carleasoft.mps.core.result.R;
import com.carleasoft.mps.core.user.ThreadUserContext;
import com.carleasoft.mps.core.user.UserCacheData;
import com.carleasoft.mps.core.utils.IBeanUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * <p>
 * 考核主表 前端控制器
 * </p>
 *
 * @author fan
 * @since 2023-05-17
 */
@RestController
@RequestMapping("/trainExam")
public class TrainExamController {
    @Autowired
    private TrainExamService trainExamService;

    /**
     * 训练考核-增加
     */
    @PostMapping("/trainExamAdd")
    public R add(@RequestBody TrainExamAddOrEditPo trainExamAddOrEditPo){
        return R.ok(trainExamService.add(trainExamAddOrEditPo));
    }





    /**
     * 训练考核-编辑
     */
    @PostMapping("/trainExamEdit")
    public R edit(@RequestBody TrainExamAddOrEditPo trainExamAddOrEditPo){
        return R.ok(trainExamService.edit(trainExamAddOrEditPo));
    }
    /**
     * 训练考核-删除
     */
    @PostMapping("/trainExamDelete")
    public R delete(@RequestBody TrainExam trainExam){
        return R.ok(trainExamService.delete(trainExam));
    }
    /**
     * 训练考核-分页查询
     */
    @PostMapping("/trainExamPageQuery")
    public R<Page<TrainExamVo>> pageQuery(@RequestBody TrainExamPageQueryPo trainExamPageQueryPo){
        return R.ok(trainExamService.pageQuery(trainExamPageQueryPo));
    }
    /**
     * 训练考核-列表查询
     */
    @PostMapping("/trainExamList")
    public R<List<TrainExam>> trainExamList(@RequestBody TrainExam trainExam){
        QueryWrapper<TrainExam> queryWrapper = new QueryWrapper<>();
        queryWrapper.orderByDesc("UPDATE_TIME");
        queryWrapper.eq("STATUS",2);
        return R.ok(trainExamService.list(queryWrapper));
    }
    /**
     * 训练考核-详情
     */
    @PostMapping("/trainExamDetail")
    public R<TrainExamAddOrEditPo> detail(@RequestBody TrainExam trainExam){
        return R.ok(trainExamService.detail(trainExam));
    }
    /**
     * 训练考核-详情(不需要token)
     */
    @PostMapping("/door/trainExamDetail")
    public R<TrainExamAddOrEditPo> doorDetail(@RequestBody TrainExam trainExam){
        return R.ok(trainExamService.detail(trainExam));
    }
    /**
     * 训练考核-成绩登记-分页查询
     */
    @PostMapping("/register/pageQuery")
    public R<Page<TrainScoreVo>> registerPageQuery(@RequestBody RegisterPageQuery registerPageQuery){
        return R.ok(trainExamService.registerPageQuery(registerPageQuery));
    }
    /**
     * 训练考核-成绩登记-详情
     */
    @PostMapping("/register/detail")
    public R<TrainScoreDetailVo> registerDetail(@RequestBody TrainScore trainScore){
        return R.ok(trainExamService.registerDetail(trainScore));
    }

    /**
     * 训练考核-成绩登记-单个登记
     */
    @PostMapping("/register/addOne")
    public R registerAddOne(@RequestBody TrainScorePo trainScorePo){
        return R.ok(trainExamService.registerAddOne(trainScorePo));
    }
    /**
     * 训练考核-成绩登记-成绩导入
     */
    @PostMapping("/register/import")
    public R registerImport(@RequestParam("file") MultipartFile file,@RequestParam("examCode") String examCode){
        return R.ok(trainExamService.registerImport(file,examCode));
    }

    /**
     * 训练考核-成绩登记-模板下载
     */
    @PostMapping("/register/download")
    public R registerDownload(HttpServletResponse response){
        return R.ok(trainExamService.registerDownload(response));
    }
    @PostMapping("/register/downloadScoreTemp")
    public R downloadScoreTemp(@RequestBody TrainExam trainExam,HttpServletResponse response){
        return R.ok(trainExamService.downloadScoreTemp(trainExam,response));
    }
    /**
     * 训练考核-
     * -模板解析
     */
    @PostMapping("/register/parse")
    public R<List<TrainScore>> registerParse(@RequestParam("file") MultipartFile file){
        return R.ok(trainExamService.registerParse(file));
    }
    /**
     *模板解析
     * */
    @PostMapping("/register/parseCopy")
    public R<List<TrainExamScorePo>> parseCopy(@RequestParam("file") MultipartFile file){
        return R.ok(trainExamService.parseCopy(file));
    }

    /**
     * 导入考核内容数据
     *
     * @param
     * @return
     */
    @PostMapping("/contentImportExcel")
    public R contentImportExcel(@RequestPart("file") MultipartFile file ) {
        List<TrainContentVo> targetItemPos = trainExamService.contentImportExcel(file);
        return R.ok(targetItemPos);
    }

    /**
     * 训练考核-成绩登记-目标对象树
     */
    @PostMapping("/register/classTree")
    public R<List<ClassTreeVo>> classTree(@RequestBody TrainExam trainExam){
        return R.ok(trainExamService.classTree(trainExam));
    }
    /**
     * 训练考核-完成登记接口
     */
    @PostMapping("/register/finish")
    public R finish(@RequestBody TrainExamFinishPo trainExamFinishPo){
        return R.ok(trainExamService.finish(trainExamFinishPo));
    }
}

